"""缩放问题测试代码"""

import time
from pynput import mouse


def mouse_Controller(x, y):
    c = mouse.Controller()
    current_pos = c.position
    if current_pos != (x, y):
        print(f"✅ 鼠标不在目标位置，正在执行移动...")
        c.position = (x, y)
        print(f'鼠标位置设置成功,现在位置位置：{c.position}')
    else:
        print(f"✅ 鼠标已在目标位置 {x, y}，无需移动。")


def on_mouse(x, y):
    print(f'f鼠标移动{x, y}')


def on_click(x, y, button, pressed):
    if button == mouse.Button.right:
        global lis
        lis.stop()
        return

    print("\n" + "=" * 40)
    print(f"📍 点击事件发生！事件报告的位置: {x, y}")

    c = mouse.Controller()
    pos_before_sleep = c.position
    print(f"📍 进入 sleep 前，鼠标实际位置: {pos_before_sleep}")

    print("⏳ 等待3秒，请观察鼠标是否被无意中移动...")
    time.sleep(3)

    pos_after_sleep = c.position
    print(f"📍 sleep 结束后，鼠标实际位置: {pos_after_sleep}")

    if pos_before_sleep != pos_after_sleep:
        print("⚠️  证据确凿：在 sleep 期间，鼠标位置发生了改变！")
    else:
        print("✅  证据：在 sleep 期间，鼠标位置没有改变。")

    print(f"🚀 现在，将强制鼠标回到点击位置: {x, y}")
    mouse_Controller(x, y)
    print("=" * 40 + "\n")


lis = mouse.Listener(
    on_move=on_mouse,
    on_click=on_click
)
lis.start()
lis.join()